<template>
<slot :controller="controller" :store="store" :model="model">
    <div :class="classNames">
        <slot name="container_scroll1Container" :controller="controller" :store="store" :model="model" >
        <AppScrollContainer 
            name="container_scroll1"
            :layoutModelDetails="store.layoutModelDetails">
            <template #container_scroll_main1>
                <slot name="container_scroll_main1Container" :controller="controller" :store="store" :model="model" >
                <AppScrollContainer 
                    name="container_scroll_main1"
                    :layoutModelDetails="store.layoutModelDetails">
                    <template #searchform>
                        <slot name="searchform" :controller="controller" :store="store" :model="model"  :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
                        <AppCtrlPos name="searchform" :layoutModelDetails="store.layoutModelDetails">
                            <slot name="IBIZOrderDefaultSearchForm" :controller="controller" :store="store" :model="model" :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
                                <IBIZOrderDefaultSearchForm
                                    :actions="{
                                        loadDraftAction: 'GetDraft'
                                    }"
                                    name="searchform"
                                    v-bind="model.ctrlParams.IBIZOrdersearchform"
                                    :context="store.context"
                                    :viewParams="store.viewParams"
                                    :closeView="store.closeView"
                                    :pLoadingHelper="store.loadingHelper"
                                    :pViewCtx="store.viewCtx"
                                    @ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
                                    @ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
                                    @ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"    />
                            </slot>
                            </AppCtrlPos>
                        </slot>
                    </template>
                    <template #grid>
                        <slot name="grid" :controller="controller" :store="store" :model="model"  :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
                        <AppCtrlPos name="grid" :layoutModelDetails="store.layoutModelDetails">
                                <slot name="IBIZOrderMainGrid" :controller="controller" :store="store" :model="model" :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
                                <IBIZOrderMainGrid
                                    :rowActiveMode='model.rowActiveMode'
                                    :actions="{
                                        loadDraftAction: 'GetDraft',
                                        createAction: 'Create',
                                        fetchAction: 'FetchDefault',
                                        removeAction: 'Remove',
                                        updateAction: 'Update'
                                    }"
                                    :defaultEnableRowEdit="model.rowEditDefault"
                                    :openView="store.openView"
                                    :newView="store.newView"
                                    :singleSelect="false"
                                    name="grid"
                                    v-bind="model.ctrlParams.IBIZOrdergrid"
                                    :context="store.context"
                                    :viewParams="store.viewParams"
                                    :closeView="store.closeView"
                                    :pLoadingHelper="store.loadingHelper"
                                    :pViewCtx="store.viewCtx"
                                    @ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
                                    @ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
                                    @ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"></IBIZOrderMainGrid>
                                </slot>
                        </AppCtrlPos>
                        </slot>
                    </template>
                </AppScrollContainer>
                </slot>
            </template>
            <template #container_scroll_header1>
                <slot name="container_scroll_header1Container" :controller="controller" :store="store" :model="model" >
                <AppScrollContainer 
                    name="container_scroll_header1"
                    :layoutModelDetails="store.layoutModelDetails">
                    <template #container_grid1>
                        <slot name="container_grid1Container" :controller="controller" :store="store" :model="model" >
                        <AppSimpleFlexContainer 
                            name="container_grid1"
                            :layoutModelDetails="store.layoutModelDetails">
                            <template #container1>
                                <slot name="container1Container" :controller="controller" :store="store" :model="model" >
                                <AppSimpleFlexContainer 
                                    name="container1"
                                    :layoutModelDetails="store.layoutModelDetails">
                                    <template #view_pagecaption>
                                        <slot name="view_pagecaption" :controller="controller" :store="store" :model="model"  :actions="{ handleComponentAction }">
                                        <AppPresetCaption 
                                            v-if="model.showCaption && !noViewCaption"
                                            name="view_pagecaption"
                                            @component-action="(actionParam: IEvent<string>) => { handleComponentAction(controller, actionParam) }"
                                            :layoutModelDetails="store.layoutModelDetails">
                                            {{model.caption}}
                                        </AppPresetCaption>
                                        </slot>
                                    </template>
                                </AppSimpleFlexContainer>
                                </slot>
                            </template>
                            <template #container3>
                                <slot name="container3Container" :controller="controller" :store="store" :model="model" >
                                <AppSimpleFlexContainer 
                                    name="container3"
                                    :layoutModelDetails="store.layoutModelDetails">
                                    <template #quicksearchbar>
                                        <slot name="quicksearchbar" :controller="controller" :store="store" :model="model"  :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
                                        <AppCtrlPos name="quicksearchbar" :layoutModelDetails="store.layoutModelDetails">
                                            <slot name="ViewQuickSearch" :controller="controller" :store="store" :model="model" :actions="{ handleQuickSearch }">
                                            <AppQuickSearch @search="(searchValue:string) => handleQuickSearch(controller, searchValue)" />
                                            </slot>
                                        </AppCtrlPos>
                                        </slot>
                                    </template>
                                </AppSimpleFlexContainer>
                                </slot>
                            </template>
                            <template #container2>
                                <slot name="container2Container" :controller="controller" :store="store" :model="model" >
                                <AppSimpleFlexContainer 
                                    name="container2"
                                    :layoutModelDetails="store.layoutModelDetails">
                                    <template #toolbar>
                                        <slot name="toolbar" :controller="controller" :store="store" :model="model"  :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
                                        <AppCtrlPos name="toolbar" :layoutModelDetails="store.layoutModelDetails">
                                            <slot name="ViewToolbar" :controller="controller" :store="store" :model="model" :actions="{ handleToolbarItemClick }">
                                                <AppToolbar
                                                    name="toolbar"
                                                    mode="DEFAULT"
                                                    :items="store.toolbarItems"
                                                    :loading="store.loadingHelper.isLoading"
                                                    @item-click="(name: string, event: MouseEvent, logic: any) => { handleToolbarItemClick(controller, name, event, logic) }">
                                                </AppToolbar>
                                            </slot>
                                            </AppCtrlPos>
                                        </slot>
                                    </template>
                                </AppSimpleFlexContainer>
                                </slot>
                            </template>
                        </AppSimpleFlexContainer>
                        </slot>
                    </template>
                </AppScrollContainer>
                </slot>
            </template>
        </AppScrollContainer>
        </slot>
    </div>
</slot>
</template>
<script setup lang="ts">
// 基于template/src/views/{{appModules}}/{{pages@DEGRIDVIEW}}/{{spinalCase page.codeName}}-base.vue.hbs生成
import { AppCtrlPos, AppScrollContainer, AppSimpleFlexContainer, AppStandardContainer, AppTabPanel, AppTabPage } from '@components/layout-element/structure';

import IBIZOrderMainGrid from '@widgets/ibiz-order/main-grid/main-grid.vue';
import IBIZOrderDefaultSearchForm from '@widgets/ibiz-order/default-searchform/default-searchform.vue';
import { AppToolbar } from '@components/widgets/toolbar';

import { useProps, useBasic, useAction, useController } from './ibiz-order-usr-2-grid-view-hook';
import { IEvent, GridViewActionType, IGridViewAbility, IGridViewStore, IParam } from '@/core';

// 输入参数
const props = defineProps(useProps());

// 基础数据
const { getClassNames, 
	getSearchFormSlotName, 
	model, 
	useNavParamsBind,
	useEventBind,
  	handleQuickGroupValueChange,
  	handleQuickSearch,
  	handleToolbarItemClick,
    handleComponentAction,
	handleCtrlAction,
	handleCtrlInit,
	handleCtrlDestroy 
	} = useBasic(props);

const emit = defineEmits<{
    (event: 'view-action', name: string, action: GridViewActionType, data: IParam[]): void;
    (event: 'view-init', name: string, data: IGridViewAbility): void;
    (event: 'view-mounted', name: string, data: IParam): void;
    (event: 'view-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
  	return getClassNames(props);
});

const searchFormSlotName = computed(() => {
  	return getSearchFormSlotName(props);
});

// 初始化控制器
const controller = useController(props, evt);

useNavParamsBind(controller, props);

const store: IGridViewStore = controller.getStore();

onMounted(() => {
    controller.viewMounted();
})

onUnmounted(() => {
    controller.viewDestroy();
})
</script>
